Skip to main content

IF ELSEIF ENDIF

[[IF:logical_condition]] … [[ELSEIF]] … [[ENDIF]]

The actions associated with IF provide versatility to QuestDown automations. In short, by using IF and other commands (according to the syntax specified below), Events and Actions can be created that depend on certain Variables and may vary during the game. For example, a door might be closed, but after pulling a lever, it might become open. Or a monster might appear only after exploring a certain room, etc. In practical terms, this is achieved through one or more "If... then..." statements. For those unfamiliar with programming languages, understanding the principles used for IF and other commands may not be immediate. In these cases, it can be useful to see the examples below and use them as a starting point to develop your own automations.

Each Variable initially has a value of 0.

The IF action works by first performing a logical condition (see below). If the result of the logical condition is "True," the subsequent text is displayed and/or the actions present until the [[ELSEIF]] or [[ENDIF]] block are executed. If it is "False," the subsequent text is displayed and/or the actions present between the [[ELSEIF]] and [[ENDIF]] blocks are executed. The [[ELSEIF]] block is optional:

  • Example 1: {[[(P), ON_OPEN(R24)]] [[IF: GET(lever) = 1]] You unlocked the door by pulling the lever before, so you can open the door! [[OPEN(S23)]] [[ELSEIF]] [[LOCKED]] [[ENDIF]]}

In the above example, the displayed text depends on the value of the "lever" Variable. If the "lever" Variable is equal to 1, the message "You unlocked the door by pulling the lever ..." appears. Otherwise, no special message appears, and the door simply remains closed (remember that each Variable has an initial value of zero). An Event with an IF usage as just exemplified could follow, for example, another preceding command in which the lever variable was set to 1. For example.
  • Example 2: {[[(K), ON_ENTER_ROOM:REPEAT]], [[ASK: Inside the room there is a lever., Do you want to pull it?]] You hear a strange sound from a nearby room [[SET(lever, 1]] [[END]]}
Note that in this case, the lever can be pulled multiple times, in fact every time you enter the room. But once it has the value 1, every time it is pulled, the same action is repeated, and therefore nothing changes (the value is always set to 1). NOTE: for those with programming experience, it is worth noting that it is not necessary to initialize Variables before using them.

Logical Conditions

Logical conditions involve the use of special keywords such as: TURN, RND,QUEST_OBJECTIVE_COMPLETED. In addition to these predefined keywords, it is possible to define Variables, which are names to which a value can be assigned and then used later in conditions.

These keywords must be compared with a value using logical operators =, <>, >, >=, <, <= with absolute values, such as numbers or texts. The operators allow checks that can result in "True" or "False".

  • Example 1: [[IF: GET(lever) = 1]]
This example code checks that the "lever" Variable has a value of 1. If the value is 1, then the logical condition results in "True"; in all other cases where the lever does not have a value = 1, the result is "False".
  • Example 2: [[IF: TURN > 3]]
This example code checks that the "TURN" Variable has a value greater than 3. For all values greater than 3, the result of the logical condition will be "True"; for values of 1 or 2, the result of the logical condition will be "False".

Below are some examples for various possibilities of using logical conditions with special keywords. For example, the code

Keywords and Logical Conditions

  • TURN indicates the current turn of the game, so an IF can be created to check if X turns have passed to perform an action or communicate a message to the players.

    • Example: {[[(T), ON_NEW_TURN]] [IF: TURN > 20]] Too much time has passed, your quest has failed! [[QUEST_FAILED]] [[ENDIF]]}
In this example, at the beginning of each player's turn, a check is made. If the Turn is greater than 10, then the message "Too much time has passed, .." appears, and the Quest concludes with a failure. Note that as always for QuestDown, it is necessary to associate the Event with a Marker. In this case, since we use ON_NEW_TURN, it can be at any point on the board.
  • RND(FROM,TO) is used to generate a random number, generating a number between the provided FROM and TO numbers.

    • Example: {[[(A), ON_SEARCH_TREASURES]] [IF: RND(1,5) = 5]] You are lucky! You found 100 Gold coins! [[ELSEIF]] You don’t find anything [[ENDIF]]}

  • QUEST_OBJECTIVE_COMPLETED is essentially a default Variable indicating whether the Quest objective has been reached. This operator is normally set to 0 unless the [[QUEST_OBJECTIVE_COMPLETED]] action has been used previously, in which case it will have a value of 1.

    • Example: {[[(U), ON_DEATH(P11)]] [[IF: QUEST_OBJECTIVE_COMPLETED = 1]] You have successfully killed Grutgar and found the scroll Now you can escape from the dungeon [[ELSEIF]] Oh no! You killed the evil wizard before finding the secret scroll that you were sent to find. You have failed! [[QUEST_FAILED]] [[ENDIF]])]]}

In this example, after killing a monster that was in cell P11, only if QUEST_OBJECTIVE_COMPLETED is equal to 1, the text "You have successfully killed ..." appears; otherwise, the text "Oh no! you killed the evil wizard .." appears, and the Quest fails.
  • GET(name) is used to retrieve the value of a variable previously assigned with [[SET(name,value)]].
    • Example: {[[(A), ON_OPEN(N23)]] [[IF: GET(key) = 1]] You have the Key so you can open this door! [[OPEN(S23)]] [[ELSEIF]] [[LOCKED]] [[ENDIF]]}

In this example, if the key variable has a value of 1, then the text "You have the Key so you can open this door" appears. Otherwise, the door is locked. Remember that each Variable has an initial value of 0. Note that programmed in this way, the action will occur with any hero attempting to open the door. However, a more complex automation can be created with ASK that can create a combination.

{[[(A), ON_OPEN(O23)]] [[IF: GET(key) = 1]] [[ASK: Do you have the key?]] The door is now open [[OPEN(S23)]] [[ELSE]] [[LOCKED]] [[END]] [[ELSEIF]] [[LOCKED]] [[ENDIF]]}

In this case, what happens is that after attempting to open the door, the phrase "Do you have the key?" appears, and only if the answer is yes, then the door will open. In all other cases, the door remains locked.